package com.keyancompany.zhongbaopingtai.activity;

import android.app.Activity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.Constants;
import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.api.CircleAPI;
import com.keyancompany.zhongbaopingtai.listener.IAsyncHttpResponseHandler;
import com.keyancompany.zhongbaopingtai.utils.T;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by firefox on 2017/6/28.
 */

public class CreateCircleThemeActivity extends BaseActivity {
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.title)
    EditText title;
    @Bind(R.id.content)
    EditText content;
    @Bind(R.id.submit)
    TextView submit;

    private String pid;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_create_circle_theme;
    }

    @Override
    protected int getMenuId() {
        return 0;
    }

    @Override
    protected void initToolBar() {
        initToolBar(toolbar, "创建话题");
    }

    @Override
    protected void setUpViews() {
        pid = getIntent().getStringExtra(Constants.TEAM_ID);
    }

    @OnClick(R.id.submit)
    public void setSubmit(View view) {
        if (TextUtils.isEmpty(title.getText().toString())) {
            T.showShort(this, "请输入话题标题！！");
            return;
        }
        if (TextUtils.isEmpty(content.getText().toString())) {
            T.showShort(this, "请输入话题内容！！");
            return;
        }
        CircleAPI.topicRequest(pid, title.getText().toString(),
                content.getText().toString(), new IAsyncHttpResponseHandler() {
                    @Override
                    public void start(int type) {

                    }

                    @Override
                    public void success(int type, String json) {
                        if (validateJson(json).isSuccess()) {
                            setResult(Activity.RESULT_OK);
                            CreateCircleThemeActivity.this.finish();
                        }
                    }

                    @Override
                    public void failed(String error) {

                    }

                    @Override
                    public void finish(int type) {

                    }
                }, getLoading(R.string.watting_hint));
    }
}
